<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/5/31
  Time: 12:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int serverPort = request.getServerPort();
    String contextPath = request.getContextPath();

    String basePath = scheme + "://" + serverName + ":" + serverPort + contextPath + "/";
%>
<base href="<%=basePath%>">
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>你的课程表</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">你的课程表</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <!-- /.row -->
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">课程信息</h3>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body table-responsive p-0">
                            <div id="coursesTable"></div>
                        </div>
                        <!-- /.card-body -->
                    </div>
                    <!-- /.card -->
                </div>
            </div>
            <!-- /.row -->
        </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
</div>
<script src="common/js/Timetables.min.js"></script>
<script>

    var list=[${sessionScope.courses}];
    console.log(list);
    console.log(list[1].week);
    var tableList = [];
    for (let k = 1; k <= 7; k++) {
        var sList = [];
        for (var m = 1; m <= 15; m++) {
            var kill = false;
            for (var i = 0; i < list.length; i++) {
                var week1 = Number(list[i].week);
                if( week1 == k){
                    if(m >= Number(list[i].begin1) && m <= Number(list[i].end1)){
                        sList.push(list[i].cName);
                        kill = true;
                    }
                }
            }
            if(!kill){
                kill = false;
                sList.push('');
            }
        }
        tableList.push(sList);
    }
    console.log(tableList);
    console.log("此处");
    // var courseList = [
    //     ['大学英语(Ⅳ)@10203', '大学英语(Ⅳ)@10203', '', '', '', '', '毛概@14208', '毛概@14208', '', '', '', '选修'],
    //     ['', '', '信号与系统@11302', '信号与系统@11302', '模拟电子技术基础@16204', '模拟电子技术基础@16204', '', '', '', '', '', ''],
    //     ['大学体育(Ⅳ)', '大学体育(Ⅳ)', '形势与政策(Ⅳ)@15208', '形势与政策(Ⅳ)@15208', '', '', '电路、信号与系统实验', '电路、信号与系统实验', '', '', '', ''],
    //     ['', '', '', '', '电装实习@11301', '电装实习@11301', '', '', '', '大学体育', '大学体育', ''],
    //     ['', '', '数据结构与算法分析', '数据结构与算法分析', '', '', '', '', '信号与系统', '信号与系统', '', ''],
    // ];
    var week = window.innerWidth > 360 ? ['周一', '周二', '周三', '周四', '周五','周六','周日'] :
        ['一', '二', '三', '四', '五','六','日'];
    var day = new Date().getDay();
    var courseType = [
        [{index: '1'}, 1],
        [{index: '2'}, 1],
        [{index: '3'}, 1],
        [{index: '4'}, 1],
        [{index: '5'}, 1],
        [{index: '6'}, 1],
        [{index: '7'}, 1],
        [{index: '8'}, 1],
        [{index: '9'}, 1],
        [{index: '10'}, 1],
        [{index: '11'}, 1],
        [{index: '12'}, 1],
        [{index: '13'}, 1],
        [{index: '14'}, 1],
        [{index: '15'}, 1]
    ];
    // 实例化(初始化课表)
    var Timetable = new Timetables({
        el: '#coursesTable',
        timetables: tableList,
        week: week,
        timetableType: courseType,
        highlightWeek: day,
        gridOnClick: function (e) {
            alert(e.name + '  ' + e.week + ', 第' + e.index + '节课, 课长' + e.length + '节');
            console.log(e);
        },
        styles: {
            Gheight: 50
        }
    });

</script>

